<!-- 好友列表 -->
<template>
  <div class="friend-list">
    <ul>
      <li v-for="item in searchedFriendList" :class="{ no_border: !item.initial}" class="friend-item">
        <div v-if="item.initial" class="list_title">{{ item.initial }}</div>
        <div :class="{ active: item.id === selectFriendIndex }" class="friend-info" @click="selectFriend(item.id)">
          <img :src="item.img" class="avatar" height="36" width="36">
          <div class="remark">{{ item.remark }}</div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import { mapActions, mapGetters, mapState } from 'vuex'

export default {
  name: 'FriendList',
  computed: {
    ...mapState([
      'selectFriendIndex',
      'searchText'
    ]),
    ...mapGetters([
      'searchedFriendList'
    ])
  },
  methods: {
    ...mapActions([
      'selectFriend'
    ])
  }
}
</script>

<style lang="stylus" scoped>
.friend-list
  height: 540px
  overflow-y: auto

  .friend-item
    border-top: 1px solid #dadada

    &:first-child, &.no_border
      border-top: none

    .list_title
      box-sizing: border-box
      width: 100%
      font-size: 12px
      padding: 15px 0 3px 12px
      color: #999

    .friend-info
      display: flex
      padding: 12px
      transition: background-color .1s
      font-size: 0

      &:hover
        background-color: rgb(220, 220, 220)

      &.active
        background-color: #c4c4c4

      .avatar
        border-radius: 2px
        margin-right: 12px

      .remark
        font-size: 14px
        line-height: 36px

</style>
